<template>
  <div style="padding:20px;">
    <template>
      <div style="width:30%; float:left; margin-right:20px;">
        <el-input v-model="currentData.money">
          <template slot="append">
            %
          </template>
        </el-input>
      </div>
      <el-button type="primary"
                 style="float:left;"
                 @click="mdfData">修改</el-button>
    </template>
  </div>
</template>

<script>
export default {
  name: "spread",
  data () {
    return {
      currentNum: '', //分佣
      oldNum: '',
      currentData: {}//返回的数据
    }
  },
  methods: {
    async init () { //初始化
      let res = await this.api.spread({})
      this.currentData = res.data;
      this.oldNum = res.data.money;
    },
    async mdfData () { //修改数据
      if (this.oldNum == this.currentData.money) return false;
      this.oldNum = this.currentData.money;
      let res = await this.api.setSpread({ money: this.currentData.money, id: this.currentData.id })
      this.$message({
        message: res.msg,
        type: res.code === 1 ? 'success' : 'error'
      })
    }
  },
  mounted () {
    this.init()
  }

}
</script>

<style scoped lang="scss">
</style>
